package edu.gatech.cs2340.group7.wheresmystuffapp.model;

import com.google.android.maps.MapActivity;

import android.content.Context;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;

/**
 * Used to call map and location based methods
 * @author tbowling3
 *
 */
public class CustomLocation extends MapActivity {
	public static String incorrectEntry = "Incorrect Entry";
	
	public CustomLocation() {
		
	}
	
	/**
	 * Converts the given string to the location formated as used by the app
	 * @param in String to be used
	 * @return
	 */
	public static String convertLocation(String in) {
		String out;
		
		if(in != null) {
			out = in;
		}
		else {
			out = "No Location";
		} // close else
		return out;
	} // close convertLocation
	
	
	public static String convertLatLongtoString(int latitude, int longitude) {
		String out = "";
		
		if(checkLatitude(latitude) && checkLongitude(longitude)) {
			
		}
		else {
			out = incorrectEntry;
		}
		
		return out;
	}
	
	private static boolean checkLatitude(int latitude) {
		boolean out = false;
		if(latitude > -90 && latitude < 90) {
			out = true;
		}
		return out;
	}
	
	private static boolean checkLongitude(int longitude) {
		boolean out = false;
		if(longitude > -180 && longitude < 180) {
			out = true;
		}
		return out;
	}


	public ItemLocation selectLocation() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public ItemLocation getCurrentLocation() {
		LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
		Criteria crit = new Criteria();
		String towers = lm.getBestProvider(crit, false);
		Location location = lm.getLastKnownLocation(towers);
		
		int lat = 0, lon = 0;
		if(location != null) {
			lat = (int) (location.getLatitude() * 1E6);
			lon = (int) (location.getLongitude() * 1E6);
		}
		ItemLocation out = new ItemLocation(lat, lon);
		
		return out;
	}

	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
} // close class Location
